com.mahees.jobTracker.models.JobPage = Backbone.Model.extend({
	defaults : function() {
		return {
			lastSyncTime : false,
			pageUrl : '',
			dataElement : '', // div to check
			name : '',
			description : '',
			approvalStatus : '',
			pageLastChanged : false,
			changes : 0,
			added : '',
			removed : ''
		};
	},

	url : function() {
		var base = '../rest/jobSite';
		if (this.isNew())
			return base;
		return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;
	},

	// https://github.com/n-time/backbone.validations
	validate : {
		name : {
			required : true,
			minlength : 3,
			maxlength : 100
		},
		pageUrl : {
			required : true,
			minlength : 3,
			type : "url"
		},
		description : {
			maxlength : 255
		}
	},

	checkChanges : function() {
		var self = this;
		$.ajax({
			url : '../default/proxyRequest',
			data : {
				pageUrl : this.get('pageUrl')
			},
			type : 'GET',
			success : function(data) {
				var html = $(self.get('dataElement'), data).html()

				if (self.get('dataValue') != html) {
					console.log('updated')
					self.set({
						lastSyncTime : new Date(),
						dataValue : html,
						unread : true
					});
					self.save();
				}
			},
			// TODO: use xml
			dataType : 'html'
		});

		// $.getJSON(this.get('pageUrl'), function(data) {
		// console.log(data)
		// self.set({
		// lastSyncTime : new Date(),
		// dataValue : data
		// });
		// self.save();
		// });
	}
});

com.mahees.jobTracker.collections.JobPages = Backbone.Collection.extend({
	model : com.mahees.jobTracker.models.JobPage,

	// localStorage : new Store("JobPages")
	url : function() {
		return '../rest/jobSites';
	}
});
